<?php
namespace app\we\controller;
use think\Controller;
use think\helper\Time;


class Update extends Controller{


    public function index(){
      set_time_limit(0);
      $olds=db('OldWechatMember')->field('openid,mobile,nickname,amount,score')->where('(amount>0 or score>0) and aid=2')->select();
      echo count($olds);
      // mylog($olds);
      foreach ($olds as $key => $value) {
       if ($value['mobile'])$have=db('WeFansCfo')->where('mobile',$value['mobile'])->find();
       if ($value['openid'])$have=db('WeFansCfo')->where('openid',$value['openid'])->find();
      
       if ($have){
              $data['amount']=$value['amount'];
              $data['score']=$value['score'];
              $res= db('WeFansCfo')->whereOr('mobile',$value['mobile'])->whereOr('openid',$value['openid'])->update($data);
              echo '更新</br>';
            }else{
              $data['aid']=2;
              $data['openid']=$value['openid'];
              $data['mobile']=$value['mobile'];
              $data['amount']=$value['amount'];
              $data['score']=$value['score'];
              $data['status']=1;
              $data['create_time']=time();
              $table=db('WeFansCfo');
              $res=$table->insert($data);
              mymysql($table);
               echo '插入</br>';
       }
          
      }
     
  
       
    }

   
}